/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package events.animation;

import gui.SnazzySpritesGUI;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import snazzysprites.SnazzySprites;
import state.Animation;
import state.Pose;
import state.SnazzySpritesState;
import state.SnazzySpritesStateManager;
import state.SpriteType;
import static snazzysprites.SnazzySpritesSettings.*;

/**
 * Handles the request to copy the current animation
 * @author Andrew Gratta <andrew.gratta@stonybrook.edu>
 */
public class CopyAnimationHandler implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        SnazzySprites singleton = SnazzySprites.getSnazzySprites();
        SnazzySpritesStateManager manager = singleton.getStateManager();
        SnazzySpritesGUI gui = singleton.getGUI();
        Animation anim = manager.getAnimation();
        if (anim != null)
        {
            String name = JOptionPane.showInputDialog(gui, ANIMATION_NAME_REQUEST_TEXT,
                ANIMATION_NAME_REQUEST_TITLE_TEXT, JOptionPane.QUESTION_MESSAGE);
            name = name.trim();
            if (!name.isEmpty() && name.length() < 20 && manager.getSpriteType().getAnimation(name) == null)
            {
                Animation newAnim = anim.clone();
                newAnim.setName(name);
                SpriteType currentSpriteType = manager.getSpriteType();
                currentSpriteType.addAnimation(newAnim);
                manager.setAnimation(name);
                gui.setAnimationComboBoxItems(manager.getAnimationNames());
                manager.setState(SnazzySpritesState.SELECT_POSE_STATE);
            }
        }
    }
    
}
